/**
 * (C) Copyright IBM Corp. 2017, 2020.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

import Foundation

/**
 Information about a word from a custom language model.
 */
public struct Word: Codable, Equatable {

    /**
     A word from the custom model's words resource. The spelling of the word is used to train the model.
     */
    public var word: String

    /**
     _For a custom model that is based on a previous-generation model_, an array of as many as five pronunciations for
     the word. The array can include the sounds-like pronunciation that is automatically generated by the service if
     none is provided when the word is added to the custom model; the service adds this pronunciation when it finishes
     processing the word.
     _For a custom model that is based on a next-generation model_, this field does not apply. Custom models based on
     next-generation models do not support the `sounds_like` field, which is ignored.
     */
    public var soundsLike: [String]

    /**
     The spelling of the word that the service uses to display the word in a transcript. The field contains an empty
     string if no display-as value is provided for the word, in which case the word is displayed as it is spelled.
     */
    public var displayAs: String

    /**
     _For a custom model that is based on a previous-generation model_, a sum of the number of times the word is found
     across all corpora and grammars. For example, if the word occurs five times in one corpus and seven times in
     another, its count is `12`. If you add a custom word to a model before it is added by any corpora or grammars, the
     count begins at `1`; if the word is added from a corpus or grammar first and later modified, the count reflects
     only the number of times it is found in corpora and grammars.
     _For a custom model that is based on a next-generation model_, the `count` field for any word is always `1`.
     */
    public var count: Int

    /**
     An array of sources that describes how the word was added to the custom model's words resource.
     * _For a custom model that is based on previous-generation model,_ the field includes the name of each corpus and
     grammar from which the service extracted the word. For OOV that are added by multiple corpora or grammars, the
     names of all corpora and grammars are listed. If you modified or added the word directly, the field includes the
     string `user`.
     * _For a custom model that is based on a next-generation model,_ this field shows only `user` for custom words that
     were added directly to the custom model. Words from corpora and grammars are not added to the words resource for
     custom models that are based on next-generation models.
     */
    public var source: [String]

    /**
     If the service discovered one or more problems that you need to correct for the word's definition, an array that
     describes each of the errors.
     */
    public var error: [WordError]?

    // Map each property name to the key that shall be used for encoding/decoding.
    private enum CodingKeys: String, CodingKey {
        case word = "word"
        case soundsLike = "sounds_like"
        case displayAs = "display_as"
        case count = "count"
        case source = "source"
        case error = "error"
    }

}
